var stepId = $CertusJsonAjax.getStepInstanceId();
var processId = $CertusJsonAjax.getProInstanceId();
$CertusFormAjax.ajax('findWaitInfo',{"processId":processId},function (response) {
    var data = response.data.appInfo;
    $$scope.id = data.id;
    $$scope.tripNum = data.trip_num;
    $$scope.userName = data.user_name;
    $$scope.planStime = data.trip_star_time;
    $$scope.planEtime = data.trip_end_time;
    $$scope.deptName = data.department_name;
    var bugetInfo = response.data.bugetInfo;
    $$scope.spMoney = 0;
    $$scope.wspMoney = 0;
    for (var i=0;i<bugetInfo.length;i++){
        if (bugetInfo[i].status==1){
            $$scope.spMoney = bugetInfo[i].buget;
        }else {
            $$scope.wspMoney = bugetInfo[i].buget;
        }
    }
    if(data.type==1){
        $$scope.type ="出差";
    }else{
        $$scope.type ="公干";
    }
});
$CertusFormAjax.ajax('findCCWaitInfo',{"processId":processId},function (response) {
    var data = response.data;
    var plans = [];
    var isShow = false;
    $$scope.isHasSping=0;
    $$scope.isTg=false;
    for (var i=0;i<data.length;i++){
        if (data[i].proPlans[0].planResult==0){
            data[i].proPlans[0].planResult="待审批";
            $$scope.isHasSping=1;
        }else if (data[i].proPlans[0].planResult==1){
            data[i].proPlans[0].planResult="待审批";
            $$scope.isHasSping=1;
        }else if (data[i].proPlans[0].planResult==2){
            data[i].proPlans[0].planResult="退回";
            $$scope.isHasSping=1;
        }else if (data[i].proPlans[0].planResult==3){
            data[i].proPlans[0].planResult="拒绝";
        }else if (data[i].proPlans[0].planResult==4){
            data[i].proPlans[0].planResult="审批通过";
            isShow=true;
            $$scope.isTg = true;
        }else if (data[i].proPlans[0].planResult==5){
            data[i].proPlans[0].planResult="主动取消";
            isShow=true;
        }else{
            data[i].proPlans[0].planResult="出差结果审批通过";
        }
        data[i].proPlans[0].bugetsl = data[i].bugets;
        data[i].proPlans[0].stUserName = data[i].stUserName;
        plans.push(data[i].proPlans[0]);
    }
    $$scope.isCtj = isShow;
    $$scope.plans = plans;
});

//取消申请
$(".down").on('click',function () {
    $CertusFormAjax.ajax('shutdownWait',{"id":$$scope.id,"stepId":stepId,"processId":processId},function (response) {
        layer.msg("取消成功！");
        window.history.back();
    });
});
//提交申请
$(".agree").on('click',function () {
    if ($$scope.isHasSping==1){
        layer.msg("你有出差项目正在审批中,请等待");
        return;
        // layer.confirm('你有出差项目正在审批中，是否确定提交？', {
        //     btn: ['确定', '取消'] //按钮
        // }, function () {
        //     if ($$scope.isTg){
        //         $CertusFormAjax.ajax('commitWait',{"id":$$scope.id,"stepId":stepId,
        //             "processId":processId},function () {
        //             layer.msg("申请成功！");
        //             window.history.back();
        //         });
        //     }else{
        //         layer.msg("本次子流程项目全部未审批通过，请点击取消申请结束流程");
        //         return;
        //     }
        // });
    }else{
        if ($$scope.isTg){
            $CertusFormAjax.ajax('commitWait',{"id":$$scope.id,"stepId":stepId,
                "processId":processId},function () {
                layer.msg("申请成功！");
                window.history.back();
            });
        }else{
            layer.msg("本次子流程项目全部未审批通过，请点击取消申请结束流程");
            return;
        }
    }
});